{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Solution:\n",
    "    def addBinary(self, a: str, b: str) -> str:\n",
    "        len_a, len_b = len(a), len(b)\n",
    "        i = 1\n",
    "        ans = \"\"\n",
    "        carry = 0\n",
    "        while i <= len_a and i <= len_b:\n",
    "            now = int(a[-i]) + int(b[-i]) + carry\n",
    "            ans = str(now % 2) + ans\n",
    "            carry = now // 2\n",
    "            i = i + 1\n",
    "        while i <= len_a:\n",
    "            now = int(a[-i]) + carry\n",
    "            ans = str(now % 2) + ans\n",
    "            carry = now // 2\n",
    "            i = i + 1  \n",
    "        while i <= len_b:\n",
    "            now = int(b[-i]) + carry\n",
    "            ans = str(now % 2) + ans\n",
    "            carry = now // 2\n",
    "            i = i + 1\n",
    "        if carry > 0:\n",
    "            ans = str(carry) + ans\n",
    "\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = \"\"\n",
    "b = \"\"\n",
    "s = Solution()\n",
    "s.addBinary(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py3",
   "language": "python",
   "name": "py3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
